/*
 * RBFTest_Broadcast.c
 *
 *  Created on: 2023年7月22日
 *      Author: mcealt_DS
 * Broadcast
 * RFM <- HUB  CMD：0x0A 同步广播
 * RFM <- HUB  CMD：0x0B 普通广播
 */
#include "net_broadcast.h"
#include "app_log.h"
#include <string.h>

#define CONFIG_LOG_RBFTEST_BROADCAST  // 模块日志宏定义,使能,模块输出日志

typedef enum
{
  RBFBROADCAST_STEP_HUB_TO_RFM,
  RBFBROADCAST_STEP_RFM_REC,
  RBFBROADCAST_STEP_FINISH,
} RBFDownloadtest_step_t;

static RBFDownloadtest_step_t step = RBFBROADCAST_STEP_HUB_TO_RFM;
static uint8_t packet[256];

void RBFBroadcasttest_LOG( void )
{
#ifdef CONFIG_LOG_RBFTEST_BROADCAST
  switch (step)
  {
  case RBFBROADCAST_STEP_HUB_TO_RFM:
    DS_app_log_debug("RBFBROADCAST_STEP is HUB_TO_RFM:\r\n");
    break;
  case RBFBROADCAST_STEP_RFM_REC:
    DS_app_log_debug("RBFBROADCAST_STEP is RFM_REC:\r\n");
    break;
  case RBFBROADCAST_STEP_FINISH:
    DS_app_log_debug("RBFBROADCAST_STEP is FINISH:\r\n");
    break;
  default:
    break;
  }
#endif
}

static uint8_t kayvalue_buf[] = {0xA1, 0xA2, 0xA3, 0xA4};
void RBFBroadcast_test(void)
{
  RBFBroadcasttest_LOG();
  switch (step)
  {
  case RBFBROADCAST_STEP_HUB_TO_RFM:
  {
    RBFMacMessageGWBoardcast_t msg = {//测试msg
        .systemId = 0x123456,
        .bretryAckCtrl = 0x03,
        .bTypeDataSize = 4,
        .bTypeData = kayvalue_buf,
    };
    memset(packet, 0, sizeof(packet));
    RBF_gw_broadcast_payload_msgToPacket(msg, packet);
    step++;
    break;
  }
  case RBFBROADCAST_STEP_RFM_REC:
  {
    RBFMacMessageGWBoardcast_t msg_rec; 
    RBF_gw_broadcast_payload_packetToMsg(packet, &msg_rec);
    step++;
    break;
  }
  case RBFBROADCAST_STEP_FINISH:
  {
    step = 0xff;
    break;
  }
  default:
    break;
  }
}
